define(function(require, exports, module) {
    'use strict';
    var rk = require('rk');
    var Treant = require('lib/treant-js/Treant')

    $.widget('rk.xsyAccountHierarchyDialog', $.rk.xsyBase, {
        options: {
            data: {}
        },
        _create: function() {
            var me = this;
            var elem = me.element;
            var opt = me.options;

            elem.attr('id', 'xsyAccountHierarchyDialog')
            elem.closest('.ui-dialog-content').css('background-color','white');

            var tpl = require('platform/widgets/crm/account/xsyAccountHierarchy/dialog/widget.tpl');
            var html = rk.templateText(tpl, {
                uuid: me.getUid()
            });
            elem.html(html);
            me._render(opt.data)
        },
        _init: function() {
            var me = this;
            var elem = me.element;
            var opt = me.options;

        },
        _render:function(json, success){
            var me = this;
            var elem = me.element;
            var opt = me.options;

            var chart_config = {
                chart: {
                    container: "#"+me.getUid()+'hierarchy',
                    levelSeparation: 45,
                    rootOrientation: "WEST",
                    nodeAlign: "BOTTOM",
                    connectors: {
                        type: "step",
                        style: {
                            "stroke-width": 2,
                            "stroke": "#e6eaf0",
                            //"stroke-dasharray": "-..", //"", "-", ".", "-.", "-..", ". ", "- ", "--", "- .", "--.", "--.."
                            "arrow-end": "none"//"classic-wide-long"
                        }
                    },
                    node: {
                        HTMLclass: "canvasnode"
                    }
                },
                nodeStructure: json
            };
            window.setTimeout(function(){
                new Treant( chart_config );
                if($.isFunction(success)) success();
            }, 10);

        }
    });
});
